home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / test / bmachinetest.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  6.2 KB  |  158 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import unittest
  5. import os
  6. import os.path as os
  7. import glob
  8. from copy import copy
  9. import httpclient
  10. import eventloop
  11. from test.framework import DownloaderTestCase
  12. ADMIN_ONLY_PAGES = [
  13.     'admin.php',
  14.     'channels.php',
  15.     'create_channel.php',
  16.     'delete.php',
  17.     'donation.php',
  18.     'donations.php',
  19.     'edit_channel.php',
  20.     'edit_videos.php',
  21.     'generate_htaccess.php',
  22.     'pause.php',
  23.     'start.php',
  24.     'stop.php',
  25.     'users.php',
  26.     'user_edit.php',
  27.     'settings.php']
  28.  
  29. class BroadcastMachineTest(DownloaderTestCase):
  30.     
  31.     def setUp(self):
  32.         self.assert_(os.environ.has_key('BMACHINE_SERVER'))
  33.         self.assert_(os.environ.has_key('BMACHINE_SERVER_LOCATION'))
  34.         self.assert_(os.environ['BMACHINE_SERVER_LOCATION'].startswith('/'))
  35.         self.assert_(os.environ.has_key('BMACHINE_SERVER_URL'))
  36.         self.assert_(os.environ.has_key('BMACHINE_LOCATION'))
  37.         self.loc = os.environ['BMACHINE_LOCATION']
  38.         self.server = os.environ['BMACHINE_SERVER']
  39.         self.server_loc = os.environ['BMACHINE_SERVER_LOCATION']
  40.         self.url = os.environ['BMACHINE_SERVER_URL']
  41.         DownloaderTestCase.setUp(self)
  42.         self.dlError = False
  43.         self.fixedPermissions = False
  44.  
  45.     
  46.     def test(self):
  47.         launchArgs = [
  48.             '-C',
  49.             '-q',
  50.             '-r']
  51.         launchArgs.extend(glob.glob(os.path.join(self.loc, '*')))
  52.         launchArgs.append('%s:%s' % (self.server, self.server_loc))
  53.         self.assertEqual(os.spawnvp(os.P_WAIT, 'scp', launchArgs), 0)
  54.         httpclient.grabURL(self.url, self.setupCallback, self.errorCallback)
  55.         self.runEventLoop()
  56.  
  57.     
  58.     def fixPermissions(self):
  59.         self.assert_(not (self.fixedPermissions))
  60.         self.fixedPermissions = True
  61.         for d in [
  62.             'torrents',
  63.             'data',
  64.             'publish',
  65.             'thumbnails',
  66.             'text']:
  67.             os.spawnlp(os.P_WAIT, 'ssh', '-C', self.server, 'mkdir %s 2>&1' % os.path.join(self.server_loc, d))
  68.             os.spawnlp(os.P_WAIT, 'ssh', '-C', self.server, 'chmod 777 %s 2>&1' % os.path.join(self.server_loc, d))
  69.         
  70.  
  71.     
  72.     def setupCallback(self, info):
  73.         self.info = info
  74.         self.assertEqual(info['status'], 200)
  75.         if info['body'].find('Before you can use Broadcast Machine, we need to create a few directories.  There are several ways to do this listed below.') != -1:
  76.             self.fixPermissions()
  77.             httpclient.grabURL(self.url, self.setupCallback, self.errorCallback)
  78.         else:
  79.             self.assertNotEqual(info['body'].find('This looks like your first time using Broadcast Machine.'), -1)
  80.             self.assertNotEqual(info['body'].find('You should create a new user account before continuing.'), -1)
  81.             httpclient.grabURL(info['redirected-url'], self.createAccountCallback, self.errorCallback, method = 'POST', postVariables = {
  82.                 'do_login': '1',
  83.                 'email': 'nassar@pculture.org',
  84.                 'username': 'admin',
  85.                 'pass1': 'PCF is cool',
  86.                 'pass2': 'PCF is cool' })
  87.  
  88.     
  89.     def makeBMCookies(self):
  90.         return {
  91.             'PHPSESSID': self.PHPSESSID,
  92.             'bm_userhash': self.bm_userhash,
  93.             'bm_username': self.bm_username }
  94.  
  95.     
  96.     def storeBMCookie(self, cookies):
  97.         if cookies.has_key('bm_userhash'):
  98.             self.bm_userhash = cookies['bm_userhash']
  99.         
  100.         if cookies.has_key('bm_username'):
  101.             self.bm_username = cookies['bm_username']
  102.         
  103.         if cookies.has_key('PHPSESSID'):
  104.             self.PHPSESSID = cookies['PHPSESSID']
  105.         
  106.  
  107.     
  108.     def createAccountCallback(self, info):
  109.         self.assertNotEqual(info['body'].find('The account admin was added successfully.'), -1)
  110.         self.assertEqual(info['cookies']['bm_username']['Value'], 'admin')
  111.         self.storeBMCookie(info['cookies'])
  112.         self.loadNoCookies(None, ADMIN_ONLY_PAGES)
  113.  
  114.     
  115.     def loadNoCookies(self, info, urllist):
  116.         if info is not None:
  117.             self.assert_(info['redirected-url'].endswith('/index.php'))
  118.         
  119.         if len(urllist) > 0:
  120.             nexturl = self.url + urllist.pop()
  121.             None((httpclient.grabURL, nexturl), (lambda info: self.loadNoCookies(info, urllist)), self.errorCallback)
  122.         else:
  123.             httpclient.grabURL(self.url + 'create_channel.php', self.createChannelLoad, self.errorCallback, method = 'POST', cookies = self.makeBMCookies(), postVariables = {
  124.                 'Name': 'Test Channel 1',
  125.                 'Description': 'This is a test channel',
  126.                 'Publisher': 'Democracy/Broadcast Machine tester',
  127.                 'Icon': 'http://images.slashdot.org/topics/topiccommunications.gif',
  128.                 'post_use_auto': '1',
  129.                 'Options[Thumbnail]': '1',
  130.                 'Options[Title]': '1',
  131.                 'Options[Creator]': '1',
  132.                 'Options[Description]': '1',
  133.                 'Options[Length]': '1',
  134.                 'Options[Filesize]': '1',
  135.                 'Options[Torrent]': '1',
  136.                 'Options[URL]': '1',
  137.                 'Options[Keywords]': '1',
  138.                 'SubscribeOptions[0]': '1',
  139.                 'SubscribeOptions[1]': '2',
  140.                 'SubscribeOptions[2]': '4' })
  141.  
  142.     
  143.     def createChannelLoad(self, info):
  144.         self.assert_(info['redirected-url'].endswith('/channels.php'))
  145.         self.assertNotEqual(info['body'].find('Test Channel 1'), -1)
  146.         self.assertNotEqual(info['body'].find('Democracy/Broadcast Machine tester'), -1)
  147.         self.assertNotEqual(info['body'].find('http://images.slashdot.org/topics/topiccommunications.gif'), -1)
  148.         self.storeBMCookie(info['cookies'])
  149.         eventloop.quit()
  150.  
  151.     
  152.     def errorCallback(self, error):
  153.         print 'Broadcast Machine URL load died with %s' % error
  154.         self.dlError = True
  155.         self.stopEventLoop()
  156.  
  157.  
  158.